package com.wxc.api.admin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wxc.api.admin.aop.MyLog;
import com.wxc.api.admin.entity.SysRole;
import com.wxc.api.admin.mapper.SysRoleMapper;
import com.wxc.api.admin.service.ISysRoleService;
import com.wxc.common.common.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 用户角色表 前端控制器
 * </p>
 *
 * @author baomidou
 * @since 2022-04-14
 */
@RestController
@RequestMapping("/api.admin/sysRole")
public class SysRoleController {

    @Autowired
    private ISysRoleService roleService;

    @Resource
    private SysRoleMapper roleMapper;

    @MyLog(value = "获取角色列表")
    @RequestMapping("list")
    @SaCheckPermission(value = "sys:role:query", orRole = "admin") // 权限认证：必须具有指定权限才能进入该方法
    public Result list(
            @RequestParam(defaultValue = "1") Integer p,
            @RequestParam(defaultValue = "10") Integer size
    ) {
        Page<SysRole> page = new Page<>(p, size);
        IPage<SysRole> iPage = roleMapper.selectPage(page, null);
        List<SysRole> records = page.getRecords();
        return Result.page(records,iPage);
    }

}
